﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiDisAutomaticDisassemblyEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CUiDisAutomaticDisassemblyEnabler : ITxCommandEnabler
{
  private bool IsReadyToEnable() => CUiDisAutomaticDisassemblyEnabler.AreCommandConditionsMet();

  public static bool AreCommandConditionsMet()
  {
    bool flag = TxAutomaticDisassembly.DynamicRoot != null;
    if (flag)
    {
      ITxOperation selectedOperation = CUiDisAutomaticDisassemblyEnabler.GetSelectedOperation();
      flag = selectedOperation != null && ((ITxObject) selectedOperation).CanBeModified;
    }
    return flag;
  }

  public static ITxOperation GetSelectedOperation()
  {
    ITxOperation selectedOperation = (ITxOperation) null;
    TxObjectList allItems = TxApplication.ActiveSelection.GetAllItems();
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxTcActivity));
    txTypeFilter.AddIncludedType(typeof (TxTcOperation));
    txTypeFilter.AddIncludedType(typeof (TxCompoundOperation));
    if (((Collection<ITxObject>) allItems).Count == 1 && txTypeFilter.DoesPassFilter(((Collection<ITxObject>) allItems)[0]))
      selectedOperation = ((Collection<ITxObject>) allItems)[0] as ITxOperation;
    return selectedOperation;
  }

  public bool Enable => this.IsReadyToEnable();
}
